package com.dailywork.basepro.lambda;

/**
 * @author Benjamin Winterberg
 */
public class Interface1 {

    private static Interface1 instance = new Interface1();

    public static Interface1 getInstance() {
        return instance;
    }

    @FunctionalInterface
    interface Formula {

        double calculate(int a);

        default double sqrt(int a) {
            return Math.sqrt(positive(a));
        }

        static int positive(int a) {
            return Math.max(a, 0);
        }
    }

    public static void main(String[] args) {
        Formula formula1 =
                new Formula() {
                    @Override
                    public double calculate(int a) {
                        return sqrt(a * 100);
                    }
                };

        formula1.calculate(100); // 100.0
        formula1.sqrt(-23); // 0.0
        System.out.println(Formula.positive(-4)); // 0.0

        //        Formula formula2 = (a) -> sqrt( a * 100);
    }
}
